package com.songlanyun.modules.thirdcallbacklog.service.impl;

import cn.hutool.core.map.MapUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.songlanyun.common.utils.PageUtils;
import com.songlanyun.common.utils.Query;
import com.songlanyun.modules.thirdcallbacklog.dao.ThirdCallBackLogDao;
import com.songlanyun.modules.thirdcallbacklog.entity.ThirdCallBackLogEntity;
import com.songlanyun.modules.thirdcallbacklog.service.ThirdCallBackLogService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;


@Service("thirdCallBackLogService")
public class ThirdCallBackLogServiceImpl extends ServiceImpl<ThirdCallBackLogDao, ThirdCallBackLogEntity> implements ThirdCallBackLogService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        String type = MapUtil.getStr(params, "type");
        String startTime = MapUtil.getStr(params, "start_time");
        String endTime = MapUtil.getStr(params, "end_time");

        IPage<ThirdCallBackLogEntity> page = this.page(
                new Query<ThirdCallBackLogEntity>().getPage(params),
                new LambdaQueryWrapper<ThirdCallBackLogEntity>()
                        .eq(StringUtils.isNotBlank(type), ThirdCallBackLogEntity::getType, type)
                        .ge(StringUtils.isNotBlank(startTime), ThirdCallBackLogEntity::getPushTime, startTime)
                        .le(StringUtils.isNotBlank(endTime), ThirdCallBackLogEntity::getPushTime, endTime)
                        .orderByDesc(ThirdCallBackLogEntity::getCreateTime)
        );

        return new PageUtils(page);
    }

}
